package com.emex.app.stuff.provider;

import com.emex.app.shared.data.JuridicalPerson;
import com.emex.app.shared.ws.JuridicalPersonWebService;
import com.emex.app.stuff.utils.WebServiceHelper;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Service;

/**
 *
 * @author Sergey
 */
public class JuridicalPersonDataProvider extends Service {

    private JuridicalPersonWebService service = null;

    private static JuridicalPersonDataProvider instance = null;

    /**
     * Constructor
     */
    private JuridicalPersonDataProvider() throws MalformedURLException {
        super(new URL(WebServiceHelper.getDefault().getWebServiceURL("web", "JuridicalPerson")),
                WebServiceHelper.getDefault().getWebServiceQName("JuridicalPerson"));
        service = getPort(JuridicalPersonWebService.class);
    }

    /**
     * Get instance of data provider.
     *
     * @return data provider instance
     */
    public static synchronized JuridicalPersonDataProvider getInstance() {
        if (instance == null) {
            new RequestWebService() {
                @Override
                protected void doRequestBody() throws MalformedURLException {
                    instance = new JuridicalPersonDataProvider();
                }
            }.doRequest();
        }
        return instance;
    }

    public BindingProvider getBindingProvider() {
        return (BindingProvider) service;
    }

    public int deleteJuridicalPersonByPrimaryKey(Integer id) {
        return service.deleteJuridicalPersonByPrimaryKey(id);
    }

    public JuridicalPerson insertJuridicalPerson(JuridicalPerson record) {
        return service.insertJuridicalPerson(record);
    }

    public JuridicalPerson selectJuridicalPersonByPrimaryKey(Integer id) {
        return service.selectJuridicalPersonByPrimaryKey(id);
    }

    public JuridicalPerson updateJuridicalPerson(JuridicalPerson record) {
        return service.updateJuridicalPerson(record);
    }

    public List<JuridicalPerson> getAllJuridicalPersons() {
        return service.getAllJuridicalPersons();
    }

    public List<JuridicalPerson> getAllJuridicalPeronsByName(String name) {
        return service.getAllJuridicalPeronsByName(name);
    }
}
